//
//  DataModel.m
//  ModelTransfer
//
//  Created by LWW on 2018/5/31.
//  Copyright © 2018年 LWW. All rights reserved.
//

#import "FNKDataModel.h"
#import <objc/runtime.h>

@implementation FNKDataModel
+(FNKDataModel *)shareModel{
    static FNKDataModel *model = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        model = [[FNKDataModel alloc] init];
    });
    return model;
}
- (NSDictionary *)dicFromObject:(NSObject *)object {
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    unsigned int count;
    objc_property_t *propertyList = class_copyPropertyList([object class], &count);
    for (int i = 0; i < count; i++) {
        objc_property_t property = propertyList[i];
        const char *cName = property_getName(property);
        NSString *name = [NSString stringWithUTF8String:cName];
        NSObject *value = [object valueForKey:name];
        if (value != nil) [dic setObject:value forKey:name];
    }
    return [dic copy];
}
@end
